/*
 * Copyright (c) 2017 22420103@QQ.COM 版权所有
 */
package com.lehe.common.utils;

import org.apache.commons.lang.time.DateUtils;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

/**
 * 日期工具类继承org.apache.commons.lang.time.DateUtils<br>
 * @see org.apache.commons.lang.time.DateUtils
 * 
 * @author 王丹
 * @FileName DateUtil.java<br>
 * @Language Java<br>
 * @date 2016-01-08<br>
 */
public class DateUtil extends DateUtils {

	public static final String yyyyMMdd = "yyyyMMdd";
	public static final String HHmmss = "HHmmss";
	public static final String yyyyMMddHHmmss = "yyyyMMddHHmmss";
	public static final String yyyyMMddHHmmssSSS = "yyyyMMddHHmmssSSS";

	public static String parseLong(Long date, String pattern) {
		Calendar c = Calendar.getInstance();
		c.setTimeInMillis(date);
		SimpleDateFormat dateFormat = new SimpleDateFormat(pattern);
		return dateFormat.format(c.getTime());
	}

	public static String getNowDateTime(String format) {
		SimpleDateFormat dateFormat = new SimpleDateFormat(format);
		return dateFormat.format(Calendar.getInstance().getTime());
	}

	public static String format(Date date, String formatStr) {

		SimpleDateFormat simpleDateFormat = new SimpleDateFormat(formatStr);
		return simpleDateFormat.format(date);
	}

	public static Date parse(String dateStr, String formatStr) throws ParseException {
		SimpleDateFormat simpleDateFormat = new SimpleDateFormat(formatStr);
		return simpleDateFormat.parse(dateStr);
	}

	public static String getDateYMD_8bit() {

		return format(new Date(), yyyyMMdd);
	}

	public static String getDateHMS_8bit(){
		return format(new Date(), HHmmss);
	}

	public static String getDateYMDHMS_14bit() {

		return format(new Date(), yyyyMMddHHmmss);
	}

	public static String getDateYMDHMSS_17bit() {

		return format(new Date(), yyyyMMddHHmmssSSS);
	}

	public static String getDateYMDHMSS_19bit() {

		return format(new Date(), "yyyy-MM-dd HH:mm:ss");
	}
}
